/* 
    镜像管理展开的子table
 */
 <template>
    <!--扩展的数据列表-->
    <el-table :show-header="false" :data="resourceC" style="width: 100%;" class="extend">
        <el-table-column width="150" prop="name" label="标签" :formatter="formatterColumn"></el-table-column>
        <el-table-column width="400" prop="pullCmd" label="pull命令" :formatter="formatterColumn"></el-table-column>
        <el-table-column width="150" prop="author" label="作者" :formatter="formatterColumn"></el-table-column>
        <el-table-column width="150" prop="created" label="创建时间" :formatter="formatterColumn"></el-table-column>
        <el-table-column label="操作">
            <template slot-scope="scope">
                <el-button icon="el-icon-delete" @click="deleteHandle(scope.$index, scope.row)" :disabled="deleteDisabled" size="small" class="small">删除</el-button>
            </template>
        </el-table-column>
    </el-table>
</template>
<script>
//scope 是父组件传递过来的
export default {
    data() {
        return {
            resourceC: [],
            deleteDisabled: true
        }
    },
    props: {
        deleteBtnDisabled: true,
        afterDeleteFun:undefined,
        scope: Object // $index/row/store  你可以看scope 这个对象，这个页面有很多简化的 
    },
    methods: {
        //格式化列表输出
        formatterColumn: function(row, column, cellValue) {
            if (column.property == 'name') {
                return "版本:" + cellValue;
            }
            if (column.property == 'pullCmd') {
                return cellValue;
            }
            if (column.property == 'author') {
                return cellValue;
            }
            if (column.property == 'created') {
                return cellValue;
            }

        },
        //根据镜像名称和版本删除镜像
        deleteHandle: function(index, row) {
            if(this.deleteDisabled){
                return;
            }
            this.$confirm('此操作有风险, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
            }).then(() => {
                let nameRepo = this.scope.row.name;
                let tag = row.name;
                let parm={
                    repoName:nameRepo,
                    tags:tag
                }
                let url = this.projectConfig.URL_API_APP_DELETE_IMAGE;
                this.httpClient.httpClientDelete(url,parm).then((response) => {
                    const code = response.meta.code;
                    if (code == this.projectConfig.CODE_OK) {
                        if (response.data) {
                            this.$message({
                                showClose: true,
                                message: '操作成功!',
                                type: 'success'
                            });
                            //this.resourceC.pop(row);
                            if(this.afterDeleteFun!=undefined){
                                this.afterDeleteFun();
                            }
                        } else {
                            this.$message({
                                showClose: true,
                                message: '操作失败',
                                type: 'warning'
                            });
                        }
                    } else {
                        let errorMsg = '异常代号为:' + code + ",异常信息:" + response.meta.message;
                        this.$message({
                            showClose: true,
                            message: errorMsg,
                            type: 'error'
                        });
                    }
                });
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消操作'
                });
            });
        },
    },
    mounted() {
        let url = this.projectConfig.URL_API_APP_IMAGES_TAG + '?repoName=' + this.scope.row.name;
        this.httpClient.httpClientget(url).then((response) => {
            // 返回处理
            const code = response.meta.code;
            if (code == this.projectConfig.CODE_OK) {
                this.resourceC = response.data;
                this.deleteDisabled = this.deleteBtnDisabled;
            } else {
                let errorMsg = '异常代号为:' + code + ",异常信息:" + response.meta.message;
                this.$message({
                    showClose: true,
                    message: errorMsg,
                    type: 'error'
                });
            }
        });
    }
}
</script>